package com.lujianfei.netease_android_mvvm_kotlin

import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner


@RunWith(
    PowerMockRunner::class
)
@PrepareForTest(MockPrivateClass::class)
class MockPrivateClassTest {

    lateinit var mMockPrivateClass: MockPrivateClass

    @Test
    @Throws(Exception::class)
    fun testMockPrivateFunc() {
        mMockPrivateClass = PowerMockito.spy(MockPrivateClass())
        PowerMockito.`when`<String>(mMockPrivateClass, "privateFunc").thenReturn("test")
        var realResult: String? = mMockPrivateClass.mockPrivateFunc()
        Assert.assertEquals("test", realResult)
        PowerMockito.verifyPrivate(mMockPrivateClass, Mockito.times(10)).invoke("privateFunc")
    }
}